﻿<UserControl
            xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
            xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
            xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
            xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
            xmlns:l="clr-namespace:EtlViewer.Viewer.Controls"
            xmlns:ctrls="clr-namespace:EtlViewer.Viewer.Controls"
            x:Class="EtlViewer.Viewer.Controls.FilterBox"
            x:ClassModifier="internal"
            Focusable="True"
            Name="userControl"
            mc:Ignorable="d"           
            d:DesignHeight="20" d:DesignWidth="300" 
            >
    <UserControl.Resources>
        <l:FilterModeIconConverter x:Key="FilterModeIconConverter" />        
        <!--Removes the dashed edge-->
        <Style TargetType="{x:Type ListBox}">
            <Setter Property="FocusVisualStyle" Value="{x:Null}"/>
        </Style>
        <Style TargetType="{x:Type Popup}">
            <Setter Property="FocusVisualStyle" Value="{x:Null}"/>
        </Style>
        <ObjectDataProvider x:Key="HistoryDS" d:IsDataSource="True" ObjectType="{x:Type l:HistoryItems}"/>
    </UserControl.Resources>
    <Grid>
        <Grid.ColumnDefinitions>            
            <ColumnDefinition Width="Auto"></ColumnDefinition>
            <ColumnDefinition Width="*"></ColumnDefinition>
        </Grid.ColumnDefinitions>
        <AdornerDecorator Grid.Column="0" >
            <ctrls:SplitButton Width="78" Margin="0,0,5,0"
                        HorizontalAlignment="Stretch"
                        Header="{Binding Path=Mode, Mode=TwoWay}"                        
                        Command="{Binding FilterCommand}"
                        MenuItem.Click="MenuItem_Click"
                        x:Name="FilterMode">
                <ctrls:SplitButton.Icon>
                    <Image Width="14" Height="14" Source="{Binding Path=Mode ,Converter={StaticResource FilterModeIconConverter}}" ></Image>
                </ctrls:SplitButton.Icon>
                <MenuItem Header="Source" ToolTip="Filter events at the source" InputGestureText="Ctrl+Shift+F">
                    <MenuItem.Icon>
                        <Image Width="14" Height="14" Source="/Assets/images/play.png" ></Image>
                    </MenuItem.Icon>
                </MenuItem>
                <MenuItem Header="View" ToolTip="Filter events in view by specifying a lambda" InputGestureText="Ctrl+Alt+F">
                    <MenuItem.Icon>
                        <Image Width="14" Height="14" Source="/Assets/images/filter.png" />
                    </MenuItem.Icon>
                </MenuItem>
                <MenuItem Header="Search" ToolTip="Highlights the text in the view" InputGestureText="Ctrl+F">
                    <MenuItem.Icon>
                        <Image Width="14" Height="14" Source="/Assets/images/search.png" />
                    </MenuItem.Icon>
                </MenuItem>
            </ctrls:SplitButton>
        </AdornerDecorator>
        <AdornerDecorator Grid.Column="1">
            <TextBox x:Name="txtFilterText"   
                     VerticalContentAlignment="Top"
                 HorizontalContentAlignment="Stretch"                  
                 KeyUp="OnFilterTextKeyUp"
                 PreviewKeyDown="txtFilterText_PreviewKeyDown"              
                 Tag="{Binding ElementName=userControl, Path=Tag}" 
                  AcceptsReturn="True">
                <TextBox.Text>
                    <Binding Path="FilterText"  Mode="TwoWay" ValidatesOnDataErrors="True">
                    </Binding>
                </TextBox.Text>                
                <l:WatermarkService.Watermark>
                    <TextBlock Padding="10,0,0,0"  VerticalAlignment="Center">SOURCE/VIEW/SEARCH TEXT FOR THE SPECIFIED FILTER MODE.</TextBlock>
                </l:WatermarkService.Watermark>
            </TextBox>
        </AdornerDecorator>
        <Button Width="22" Grid.Column="1"
                HorizontalAlignment="Right" 
				VerticalAlignment="Stretch"
				Name="BtnShowDropDown"  
				Click="BtnShowDropDown_Click"
                Margin="-11,2,2,2"
				BorderThickness="0" 
				Background="White" 
				BorderBrush="{StaticResource TextBoxBorderBrush}"
                KeyboardNavigation.IsTabStop="False">
            <Grid>
                <Polygon Points="0,0, 3,5 6,0" Fill="#FF5E6274" ></Polygon>
            </Grid>
        </Button>      
        <Popup x:Name="popupFields" Height="Auto" Width="Auto"
                PlacementTarget ="{Binding ElementName=txtFilterText}"               
                StaysOpen="False" IsOpen="false" 
                d:LayoutOverrides="Width, Margin" 
                HorizontalAlignment="Right">
            <Grid Width="Auto" Height="Auto" Background="White">
                <Border BorderBrush="LightBlue" BorderThickness="1" >
                    <ListBox x:Name="lstFields"                            
                            LostKeyboardFocus="lstFields_LostKeyboardFocus" 
                            PreviewKeyDown="lstFields_PreviewKeyDown"
                            Width="200"                         
                            SelectedIndex="0"
                            SelectionMode="Single"
                            IsTextSearchEnabled="True" 
                            ItemsSource="{Binding Path=SupportedFields ,Mode=OneWay}"        
                            BorderBrush="Transparent">
                        <ListBox.ItemContainerStyle>
                            <Style TargetType="{x:Type ListBoxItem}">
                                <EventSetter Event="MouseDoubleClick"  Handler="lstFields_MouseDoubleClick"/>
                                <EventSetter Event="MouseUp" Handler="lstItemClick"  />
                            </Style>
                        </ListBox.ItemContainerStyle>
                    </ListBox>
                </Border>
            </Grid>
        </Popup>
        <Popup x:Name="popupHistory" Height="Auto" Width="Auto" 
                StaysOpen="False" 
                Placement="Bottom" IsOpen="false"
                PlacementTarget ="{Binding ElementName=txtFilterText}" 
                d:LayoutOverrides="Width, Margin" 
                HorizontalAlignment="Left" >
            <Grid Width="Auto" Height="Auto" >
                <Border  BorderThickness="1"  BorderBrush="{DynamicResource {x:Static SystemColors.GrayTextBrushKey}}">
                    <ListBox x:Name="lstHistory" 
                            PreviewKeyDown="lstFields_PreviewKeyDown"
                            KeyUp="lstHistorySelection_KeyDown"  
                             MouseDown="lstHistory_MouseDoubleClick"
                             PreviewMouseDown="lstHistory_MouseDoubleClick"
                            SelectedIndex="0"
                            SelectionMode="Single"
                            IsTextSearchEnabled="True"                          
                            ItemsSource="{Binding History, Mode=OneWay, Source={StaticResource HistoryDS}}"         
                            LostKeyboardFocus="lstFields_LostKeyboardFocus" 
                            Width="{Binding ActualWidth, ElementName=txtFilterText}"                              
                            BorderThickness="0"                  
							ScrollViewer.VerticalScrollBarVisibility="Visible"
							Padding="2">
                        <ListBox.ItemContainerStyle>
                            <Style TargetType="{x:Type ListBoxItem}">
                                <Setter Property="Padding" Value="1" />
                                <EventSetter Event="MouseDoubleClick" Handler="lstHistory_MouseDoubleClick"  />
                                <EventSetter Event="MouseUp" Handler="lstItemClick"  />
                                <EventSetter Event="MouseEnter" Handler="lstItemClick" />
                                <EventSetter Event="PreviewMouseDown" Handler="lstItemClick" />
                            </Style>
                        </ListBox.ItemContainerStyle>
                    </ListBox>
                </Border>
            </Grid>
        </Popup>

    </Grid>
</UserControl>
